package com.jye.rseven.user.serivce.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.jye.rseven.Constants.MyConstants;
import com.jye.rseven.domain.Promotion;
import com.jye.rseven.service.PromotionService;
import com.jye.rseven.user.mapper.PaymentMapper;
import com.jye.rseven.user.mapper.PromotionMapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@Service
public class PromotionServiceImpl implements PromotionService {

    @Autowired
    PromotionMapper promotionMapper;

    @Autowired
    PaymentMapper paymentMapper;

    @Override
    public Promotion findPromotionById(int id) {
        return promotionMapper.findPromotionById(id);
    }

    @Override
    public List<Promotion> findAllPromotion(int skip, int limit) {
        return promotionMapper.findAllPromotion(skip, limit);
    }

    @Override
    public String addPromotion(Promotion promotion) {
        try{

            String payStatus=paymentMapper.findPayStatusById(promotion.getPId());
            if(payStatus== MyConstants.payStatus.paid) {
                String status = MyConstants.promotionStatus.paid;
                promotion.setStatus(status);
                promotionMapper.addPromotion(promotion);
                return "已支付!";
            }else {
                String status= MyConstants.payStatus.unpaid;
                promotion.setStatus(status);
                promotionMapper.addPromotion(promotion);
                return "未支付";
            }
        }catch (Exception e){
            return "失败!";
    }
    }

    @Override
    public int updatePromotion(Promotion promotion) {
        try{
            promotionMapper.updatePromotion(promotion);
            return 1;
        }catch (Exception e){
            return 0;
        }
    }





    @Override
    public Promotion findPromotionByShareCode(String shareCode) {
        Promotion promotion = promotionMapper.findPromotionByShareCode(shareCode);
        return promotion;
    }
}
